/*
  FileName  : FAT32.h

  This file defines FAT32 variables, constants and function ptototypes.

  Created on 2007.9.14 by ZZP.

  Revision History:

*/

#ifndef __FAT32_H__
#define __FAT32_H__

#include "ZZP_SysConstDef.h"

////////////////////////////////////////////////////////
//        FAT32 constants and variables
////////////////////////////////////////////////////////
#define FAT12 0x01
#define FAT16 0x02
#define FAT32 0x03

#define ROOT_DIR   0
#define NORMAL_DIR 1

#define ATTR_READ_ONLY    0x01
#define ATTR_HIDDEN       0x02
#define ATTR_SYSTEM       0x04
#define ATTR_VOLUME_ID    0x08
#define ATTR_DIRECTORY    0x10
#define ATTR_ARCHIVE      0x20
#define ATTR_LONG_NAME    0x0F

#define FAT_EOC   0x0FFFFFFF // Any value that >= 0x0FFFFFF8 is a valid EOC mark. 
#define FAT_FREE  0x00000000 //
#define FAT_BAD   0x0FFFFFF7 // Bad sector mark.

#define DIR_UNUSED_ENT  0xE5 //Unused.When delete a file or dir,set it's entry to this value.
#define DIR_END_OF_ENT  0x00 //End of this Directory.

//Dir or File Entry type for search
#define ENT_NEW   0x00
#define ENT_EXIST 0x01

#define FILE_LAST_PART     0
#define FILE_NOT_LAST_PART 1

#define CLUSTER_FREE       0
#define CLUSTER_USED       1


#define CF_128M 1
#define CF_256M 2
#define CF_512M 3
#define CF_1G   4
#define CF_2G   6
#define CF_4G   10 


#define MAX_BUF_LENGTH              4096
#define SEC_CNT_OF_MAX_BUF_LEN      (MAX_BUF_LENGTH >> 8)

extern volatile BPB_INFO tmpcbpb;
extern volatile DISK_INFO HDInfo;

extern unsigned int CF_Buf[2048];
extern unsigned int FAT32_Buf[MAX_BUF_LENGTH];



extern signed int FAT32_GetDiskInfo(unsigned int Disk,
                                    DISK_INFO *Info,
                                    BPB_INFO *bpb);
       /*
         Purpose : Get FAT32 informations.
         Variable modified : cbpb(hbpb)
         Params : Disk --- CF card: 0;  Hard disk drive: 1
         Return value : -1 --- Disk not formated
                         0 --- Disk is FAT12
                         1 --- Disk is FAT16
                         2 --- Disk is FAT32
       */
extern unsigned int FAT32_SetFSInfo(unsigned int Disk,
                                    BPB_INFO *bpb);
       /*
         Purpose : Get FAT32 FSInfo
         Variable modified : cfsi(hfsi)
         Params : Disk --- CF card: 0;  Hard disk drive: 1
         Return value : 0 --- Disk may not formatted
                        1 --- fsi has no error
       */
extern unsigned int FAT32_GetRootData(unsigned int Disk,
                                      DISK_INFO *Info,
                                      BPB_INFO *bpb);
                               
extern unsigned long FAT32_FormatDisk(unsigned int Disk,
                                      DISK_INFO *Info,
                                      BPB_INFO *bpb,
                                      DATE_TIME_INFO *dt,
                                      unsigned int FormatAll);
       /*
         Purpose : Format disk
         Variables modified : cbpb,cfsi(hbpb,hfsi)
         Params : Disk --- CF card: 0;  Hard disk drive: 1
         Return value : none
       */

extern unsigned long FAT32_CreateRootDir(unsigned int Disk,
                                  BPB_INFO *bpb, DATE_TIME_INFO *dt);

extern Uns FAT32_CreateBigFile(Uns Disk, BPB_INFO *bpb, DATE_TIME_INFO *dt);
extern Uns FAT32_CheckBigFile(Uns *Buf, BPB_INFO *bpb);


extern Uns FAT32_GetFileClusters(Uns Disk, BPB_INFO *bpb, LgUns *Dest, LgUns FirstCluster);


#endif



